home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / blf082b / nlist.pl < prev    next >
Perl Script  |  1993-12-15  |  2KB  |  75 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # NetList compiler, Perl clone of "nlist.c". Written by Thierry Bousch
  4. # for the BloufGate project and placed in the public domain.
  5. # Usage: nlist [-c] [--city] <nodelist> [netlist]
  6. #
  7. # The flag -c (short form) or --city (long form) appends the name of the
  8. # city to the name of the net.
  9. #
  10. # If no netlist name is provided, data will be written on standard output.
  11. #
  12.  
  13. $Usage = "Usage: nlist [-c] [--city] <nodelist> [netlist]\n";
  14. $use_cities = 0;
  15.  
  16. # Parse command line
  17.  
  18. if ($ARGV[0] eq "-c" || $ARGV[0] eq "--city") {
  19.     shift;
  20.     $use_cities = 1;
  21. }
  22.  
  23. die $Usage unless @ARGV;
  24. $nodelist = shift;
  25. $netlist  = @ARGV ? shift : "-";    # stdout if no netlist name
  26.  
  27. # Now try to open the files
  28.  
  29. open(NODELIST,  $nodelist) || die "Can't open file \"$nodelist\" !\n";
  30. open(NETLIST, ">$netlist") || die "Can't open file \"$netlist\" !\n";
  31.  
  32. print NETLIST "#\n# Nodelist \"$nodelist\" compiled with nlist.pl\n#\n";
  33.  
  34. # Scan nodelist
  35.  
  36. $net = $zone = 0;
  37.  
  38. while (<NODELIST>) {
  39.     # Remove end-of-line terminators, and ^Z if any
  40.     s/[\n\r\032]//g;
  41.     next if /^;/;        # skip comments
  42.     next if /^$/;        # and empty lines
  43.     next if /^,/;        # and those beginning with a comma
  44.  
  45.     # Break the line into its fields
  46.     ($key,$number,$name,$city) = split(/,/);
  47.  
  48.     if ($key eq "Zone") {
  49.         # New zone
  50.         $net = $zone = $number;
  51.     }
  52.     elsif ($key eq "Region" || $key eq "Net" || $key eq "Host") {
  53.         # New net
  54.         $net = $number;
  55.     }
  56.     else {
  57.         # Not a new zone or net
  58.         next;
  59.     }
  60.     
  61.     if ($net == 0 || $zone == 0) {
  62.         # This should not happen
  63.         warn "Undefined net or zone -- corrupted nodelist?\n";
  64.         next;
  65.     }
  66.  
  67.     # Write the net, replacing underscores by spaces
  68.  
  69.     $_ = "$zone:$net $name";
  70.     $_ .= " ($city)" if $use_cities;
  71.     s/_+/ /g;
  72.     print NETLIST "$_\n";
  73. }
  74.